(ns projectname.views.layout
  (:use [ring.util.response :only [content-type response]]
        [compojure.response :only [Renderable]])
  (:require [selmer.parser :as parser]
            [noir.session :as session]
            [projectname.util :as util]))

(def template-folder "projectpath/views/templates/")

(defn utf8-response [html]
  (-> (response html)
      (content-type "text/html; charset=utf-8")))

(deftype RenderablePage [template-name params]
  Renderable
  (render [this req]
    (->> (merge {:context (:context req)
                 :user    (session/get util/SESSION-USER-KEY)
                 #_"More global params here"}
                params)
         (parser/render-file (str template-folder template-name))
         utf8-response)))

(defn render [template & [params]]
  (RenderablePage. template params))